﻿using Sc.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Sc.Web.Controllers
{
    public class ReportController : BaseController
    {
        /// <summary>
        ///报表服务层
        /// </summary>
        private readonly ReportService service = new ReportService();

        /// <summary>
        /// 车辆使用次数统计
        /// </summary>
        /// <returns></returns>
        public ActionResult CarUserCount()
        {
            ViewData["olist"] = CommService.GetOrgzByUserPer(UserLogin.UserId, 7);
            return View();
        }
        /// <summary>
        /// 获取车辆使用统计
        /// </summary>
        /// <param name="orgz">机构</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <returns></returns>
        public JsonResult GetCarUserCountData(int orgz, DateTime start, DateTime end)
        {
            var list = service.GetUseCountData(orgz, start, end, 0);
            return Json(list, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 所有报表页面
        /// </summary>
        /// <returns></returns>
        public ActionResult CommReport()
        {
            int tag = Convert.ToInt32(Request.Params["tag"]);
            ViewData["tag"] = tag; var tmp = string.Empty;
            var perssionId = 0;
            switch (tag)
            {
                case 1:
                    tmp = "车辆违章统计";
                    perssionId = 8;
                    break;
                case 2:
                    tmp = "车辆保养统计";
                    perssionId = 10;
                    break;
                case 3:
                    tmp = "车辆事故统计";
                    perssionId = 11;
                    break;
                case 4:
                    tmp = "车辆加油统计";
                    perssionId = 12;
                    break;
                case 5:
                    tmp = "车辆维修统计";
                    perssionId = 13;
                    break;
                case 6:
                    tmp = "车辆保险统计";
                    perssionId = 13;
                    break;
                case 7: tmp = "保险申请统计";
                    perssionId = 33;
                    break;
            }
            ViewData["tmp"] = tmp;
            ViewData["olist"] = CommService.GetOrgzByUserPer(UserLogin.UserId, perssionId);
            return View();
        }
        /// <summary>
        /// 获取车辆报表数据
        /// </summary>
        /// <param name="orgz">机构</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="tag">报表类型</param>
        /// <returns></returns>
        public JsonResult GetCommReportData(int orgz, DateTime start, DateTime end, int tag)
        {
            var data = service.GetUseCountData(orgz, start, end, tag);
            return Json(data, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 驾驶员报表数据
        /// </summary>
        public ActionResult DriverReportData()
        {
            ViewData["olist"] = CommService.GetOrgzByUserPer(UserLogin.UserId, 33);
            return View();
        }
        /// <summary>
        /// 按照驾驶员统计
        /// </summary>
        /// <param name="orgz">机构</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <returns></returns>
        public JsonResult GetDriverReportData(int orgz, DateTime start, DateTime end)
        {
            var list = service.GetDriverData(orgz, start, end);
            return Json(list, JsonRequestBehavior.AllowGet);
        }


        public ViewResult CarUseApp() {
            ViewData["olist"] = CommService.GetOrgzByUserPer(UserLogin.UserId, 7);
            return View();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="orgz"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public JsonResult GetCarUseApp(int orgz, DateTime start, DateTime end, int pageSize, int pageIndex)
        {
            var data = new Car_UseCarApplicationService().GetList(orgz, start, end, pageSize, pageIndex);
            return Json(data, JsonRequestBehavior.AllowGet);
        }

    }
}